<template>
   <div>
      <p>test</p>
      <a-button @click="goEntBill">前往企业管理页面</a-button>
   </div>
</template>

<script>
import { debounce } from '@/utils/util'

export default {
   name: 'index',
   data () {
      return {}
   },
   methods: {
      goEntBill: debounce(function() {
         this.$router.push({ name: 'entBill' })
      }, 2000)
   },
   created () {

   },
   mounted () {
      /**
       * $route 是当前router跳转对象里面可以获取name, path, query, params等
       * $router 是VueRouter实例，想要导航到不同url, 可以使用$router.push方法
       */
      window.onbeforeunload = () => {
         if (this.$route.fullPath === '/test') {
            return '关闭提示'
         } else {
            window.onbeforeunload = null
         }
      }
   },
   destroyed () {
      window.onbeforeunload = null
   },
   beforeRouteLeave (to, from, next) {
      const answer = window.confirm('您确定要离开当前页面？')
      if (answer) {
         next()
      } else {
         next(false)
      }
   }
}
</script>

<style scoped>

</style>
